--转菊花(网络延时等情况出现)
local OverTimeMgr = class("OverTimeMgr");
function OverTimeMgr:ctor()
    self._showers = {};
    self._showerCnt = 0;
    self._sch = nil;
    self._delayTime = 2;--网络超时菊花不是立即出现
end

function OverTimeMgr:addLoading()
    self._smallLoading = display.newSprite(mgrs.res:getPngPath("mihua"));
    local par = mgrs.wnd:getLayer(enums.Layer.Locker);
    self._smallLoading:setPosition(cc.p(display.cx,display.cy));
    par:addChild(self._smallLoading);
    self._smallLoading:setVisible(false);
end

function OverTimeMgr:removeLoading()
    self._smallLoading:removeFromParent();
end

function OverTimeMgr:show(showType,showTime)
    mgrs.log:printNotice("OverTimeMgr:show %d",showType);
    self:addLoading();
    if showTime == nil then
       showTime = 900000000000;
    end
    if self._showers[showType] then
        self._showers[showType] = self._showers[showType] + showTime;
    else
        self._showers[showType] = showTime;
        self._showerCnt = self._showerCnt + 1;
        if self._showerCnt == 1 then
            mgrs.action:beginAction(self._smallLoading):DelayTime(self._delayTime):CallFunc(function()
                self._smallLoading:setVisible(true);
                mgrs.action:beginAction(self._smallLoading):RotateBy(1,360):RepeatForever():endAction();
            end):endAction();
            mgrs.input:lock(enums.Locker.OverTime);
        end
    end

    if not self._sch then
        self._sch = mgrs.scheduler:scheduleGlobal(function()
            for key, var in pairs(self._showers) do
                self._showers[key] = var - 0.1 * 1000;
                if self._showers[key] <= 0 then
                    self:hide(key);
                end
            end
        end,0.1)
    end
end

function OverTimeMgr:hide(hideType)
    mgrs.log:printNotice("OverTimeMgr:hide %d",hideType);
    if self._showers[hideType] then
        self._showers[hideType] = nil;
        self._showerCnt = self._showerCnt - 1;
        if self._showerCnt <= 0 then
            self:removeLoading();
            mgrs.scheduler:unscheduleGlobal(self._sch);
            self._sch = nil;
            mgrs.input:unLock(enums.Locker.OverTime);
        end
    end
end

mgrs.overTime = nil;
mgrs.singleClass(mgrs,OverTimeMgr,"overTime");


--endregion
